﻿var movaMsgHtml = "<div id=\"window\" style=\" display:none;\"></div>";

var _window;

var _validate;

function isValidate(id) {
    _validate = $("#" + id).kendoValidator().data("kendoValidator");
    return _validate.validate();
}

function InitWindow(infos, msg) {
    closeMsg();
    $("body").append(movaMsgHtml);
    _window = $("#window").html(msg);
    _window.kendoWindow(infos);
}

//消息框  单按钮
function alertMsg(msg, title, evt) {
    title = $.trim(title) ? title : _windowMessage[getCurrentLang()]["_title"];
    msg = "<div class='k-con-box'>" + msg + "</div><div class='k-btn-box'><input type='button' id='btnAlertMsg' onclick='closeMsg1()' value='" + _windowMessage[getCurrentLang()]["_confirmButton"] + "' class='k-btn-sure'/></div>";
    var infos = {
        width: "378px",
        height: "133px",
        title: title,
        actions: [ /*"Close"*/],
        modal: true,
        close: function() {
            if ($.isFunction(evt)) {
                evt();
            }
            deleteWindowDiv();
        }
    };
    InitWindow(infos, msg);
    windowOpen("");
}

//消息框  双按钮( 直接返回 保存并返回)
function alertMsg1(title, msg) {
    msg = "<div class='k-con-box'>" + msg + "</div><div class='k-btn-box'><a href='#' class='link' style='margin: 0 20px;*margin: -25px 20px;*display:inline-block;'>" + _windowMessage[getCurrentLang()]["_back"] + "</a><input type='button' id='btnAlertMsg' onclick='closeMsg1()' value='" + _windowMessage[getCurrentLang()]["_backWithSave"] + "' class='k-btn-sure'/></div>";
    var infos = { width: "378px", height: "133px", title: title, actions: ["Close"], modal: true, close: deleteWindowDiv() };
    InitWindow(infos, msg);
    windowOpen("");
}

function alertMsgForEvt(msg, evt, evtinit, title) {
    title = $.trim(title) ? title : _windowMessage[getCurrentLang()]["_title"];
    msg = "<div class='k-con-box'>" + msg + "</div><div class='k-btn-box'><input type='button' id='btnAlertMsgForEvt' value='" + _windowMessage[getCurrentLang()]["_confirmButton"] + "' class='k-btn-sure'/></div>";
    var infos = {
        width: "360px",
        //height: "150px",
        //height: "110px",
        title: title,
        actions: ["Close"],
        modal: true,
        close: deleteWindowDiv(),
        open: ($.isFunction(evtinit) ? evtinit : null)
    };
    InitWindow(infos, msg);
    $("#btnAlertMsgForEvt").bind("click", function() {
        closeMsg();
        if ($.isFunction(evt))
        {
            evt();
        }
    });
    //_window.data("kendoWindow").center().open();
    //setTimeout("closeMsg()", 2000);
    windowOpen("");
}

//确认消息框
function alertConfirmMsg(msg, evt1, evt2, title) {
    title = $.trim(title) ? title : _windowMessage[getCurrentLang()]["_confirmtitle"];
    var infos = {
        width: "360px",
        //height: "150px",
        //height: "110px",
        title: title,
        actions: ["Close"],
        modal: true,
        close: deleteWindowDiv()
    };
    msg = "<div class='k-con-box'>" + msg + "</div><div class='k-btn-box'><input type='button' id='btnAlertConfirmMsgCancel' value='" + _windowMessage[getCurrentLang()]["_cancalBbtn"] + "' class='k-btn-cancel'style='background: transparent; color: #323232;'/><input type='button' id='btnAlertConfirmMsg' value='" + _windowMessage[getCurrentLang()]["_formWindowconfirmButton"] + "' class='k-btn-sure'/></div>";
    InitWindow(infos, msg);
    $("#btnAlertConfirmMsg").bind("click", function() {
        closeMsg();
        if ($.isFunction(evt1))
        {
            evt1();
        }
    });

    $("#btnAlertConfirmMsgCancel").bind("click", function() {
        closeMsg();
        if ($.isFunction(evt2)) {
            evt2();
        }
    });
    //_window.data("kendoWindow").center().open();
    windowOpen("");
}

//操作框
function alertOperateWindow(winID, title, width, height, closeEvt) {
    _window = $("#" + winID).kendoWindow({
        title: title,
        width: (width + "px"),
        height: (height + "px"),
        actions: [/*"refresh", "Maximize",*/ "Close"],
        modal: true,
        visible: false,
        close: closeEvt
    });

    windowOpen(title);
};

//表单框
function alertFormWindow(url, title, width, height,evt) {
    msg = "<div class='k-btn-box'><input type='button' id='btnAlertMsgForEvt' value='" + _windowMessage[getCurrentLang()]["_confirmButton"] + "' class='k-btn-sure'/></div>";
    var infos = {
        width: width + "px",
        height: height + "px",
        title: title,
        actions: ["Close"],
        modal: true,
        iframe: true,
        content: url,      
        close: deleteWindowDiv()
    };
    InitWindow(infos, msg);
    $("#btnAlertMsgForEvt").bind("click", function () {
        closeMsg();
        if ($.isFunction(evt)) {
            evt();
        }
    });
    //_window.data("kendoWindow").center().open();
    windowOpen(title);
}

function windowOpen(title) {
    if (title != "") {
        _window.data("kendoWindow").title(title);
    }
    $("span.k-tooltip").hide();
    _window.data("kendoWindow").center().open();
}

function windowClose(target) {
    if (target != null && target!="") {
        $('#' + target).data("kendoWindow").close();
    }
}

function closeMsg() {
    try {
        $("span.k-tooltip").hide();
        _window.data("kendoWindow").close();
        deleteWindowDiv();
        waitingClose();
    } catch (e) {
        _window = null;
    }
}
function closeMsg1() {
    try {
        $("span.k-tooltip").hide();
        _window.data("kendoWindow").close();

        deleteWindowDiv();
        waitingClose();
    } catch (e) {
        _window = null;
    }
}

function deleteWindowDiv() {
    if($("body").find("#window").length > 0){
        $("body").find("#window").remove();
    }
}

function waiting() {
    var msg = "";
    var waitingHtml = "<div id=\"center-pane\" style=\"position:absolute;z-index:2;top:0px;left:0px;width:100%;height:auto;\"><span id=\"loading\"></span></div>";
    $("body").append(waitingHtml);
    $("body").find('#center-pane').height($('body').height());
    kendo.ui.progress($("body").find("#loading"), true);

    $("body").find(".k-loading-text").attr("style", "color:black;margin:336px 0px 0px 724px;text-indent:0px;");
    $("body").find(".k-loading-text").text(msg);

    //alertMsg("操作成功!");
    //setTimeout("waitingClose()", 3000);
}

function waitingClose() {
    $("body").find('#center-pane').css('height', 'auto');
    kendo.ui.progress($("body").find("#loading"), false);
}

function alertEditorWindow() {
    $.extend
}

var _windowMessage = {
    CN: {
        _title: "提示",
        _confirmButton: "确定",
        _back: "直接返回",
        _backWithSave: "保存并返回",
        _confirmtitle: "确认",
        _cancalBbtn: "取消",
        _formWindowconfirmButton: "确定",
        _countryCode: "国家码",
        _countryCodeError: "国家码有误",
        _maxLen: "最大长度不能超过",
        _payTip: "支付",
    },
    EN: {
        _title: "prompt",
        _confirmButton: "confirm",
        _back: "Direct return",
        _backWithSave: "Save and Return",
        _confirmtitle: "confirm please",
        _cancalBbtn: "cancel",
        _formWindowconfirmButton: "confirm",
        _countryCode: "CountryCode", //MobileCountryCode
        _countryCodeError: "Country code is incorrect",
        _maxLen: "The maximum length can not exceed",
        _payTip: "pay",
    },
    CH: {
        _title: "提示",
        _confirmButton: "確定",
        _back: "直接返回",
        _backWithSave: "保存並返回",
        _confirmtitle: "确认",
        _cancalBbtn: "取消",
        _formWindowconfirmButton: "确定",
        _countryCode: "國家碼",
        _countryCodeError: "国家码有误",
        _maxLen: "最大长度不能超过",
        _payTip: "支付",
    }
}